﻿ 

	
<!DOCTYPE html>  
<html>  
<head>  
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
    <meta name="keywords" content="公司员工">  
    <meta name="description" content="公司员工">  
    <title>公司员工管理</title>  
    
    <%@ include file="/WEB-INF/inc/default.jsp"%>
    <jsp:include page="/WEB-INF/inc/dic.jsp"/>

</head>  
<body>  
    
      
    <table id="dg"  style="height:550px"  
            url="/auth/systemUser/list.do?"  
            toolbar="#toolbar" pagination="true"  
            rownumbers="true" fitColumns="true" pageSize=18 pageNumber="2" pageList="[10,20,30,40,50]" loadMsg="正在查询,请稍候..." singleSelect="true">  

    </table>  
    <div id="toolbar">  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="add()">新增</a>  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="edit()">修改</a>  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="userRole()">设置用户角色</a> 
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="deletes()">删除</a>  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="find()">查询</a>
    </div>  
    <!-- edit form窗体（开始） -->  
    <div id="dlg" style="display:none;">  
        <!--    
        <form id="fm" method="post" novalidate>  
        	  	  	 <input type="hidden" name="id" > 
	        		     <div class="fitem">  
                     <label style="width:100px">用户帐号<font color="red">*</font>:</label>                                            
                     <input name="account" class="easyui-box easyui-validatebox"  required="true">                       
                   </div> 
	        		     <div class="fitem">  
                     <label style="width:100px">帐号密码<font color="red">*</font>:</label>                                            
                     <input name="passwd" class="easyui-box easyui-validatebox"  required="true">                       
                   </div>                    
                   <div class="fitem">  
                     <label style="width:100px">姓名(中):</label>                                            
                     <input name="nameCn" class="easyui-box">                       
                   </div> 
	        		     <div class="fitem">  
                     <label style="width:100px">英文名<font color="red">*</font>:</label>                                            
                     <input name="name" class="easyui-box easyui-validatebox"  required="true">                       
                   </div> 
                   
	        		     <div class="fitem">  
                     <label style="width:100px">分公司:</label>                                            
                                           
                     <input class="easyui-combobox"  id="branchCompanyIdString"  name="branchCompanyIdString" style="width:200px;"  data-options="url:'/auth/systemBranchCompany/listbranchcompany.do',valueField:'id', textField:'name', multiple:true,panelHeight:'auto',mode:'remote' "                     
                     ,onSelect: function(rec){  
            
                       //$('#userDeptId').combobox('reload', '/auth/systemBranchDept/deptlist.do?branchCompanyId=' + rec.id);  
                       //$('#userDeptId').combobox('setValues','null');
                       
                       //$('#userTitleId').combobox('loadData', {});  
                       //$('#userTitleId').combobox('setValues',null);
                     }
                     >
                   </div> 
	        		     <div class="fitem">  
                     <label style="width:100px">部门:</label>                                                                      
                     <input class="easyui-combobox" id="userDeptId" multiple="true"  name="deptId" style="width:200px;"  data-options="url:'',valueField:'id', textField:'name', multiple:true,panelHeight:'auto',mode:'remote' "
                     ,onSelect: function(rec){  
                       //alert($('#userTitleId').combobox('getValues'));
                       //console.log($('#userTitleId').combobox('getValues'));
                       //alert('cc');
                       //$('#userTitleId').combobox('reload', '/auth/systemBranchTitle/titlelistaa.do?deptId=' + rec.id);  
                       //$('#userTitleId').combobox('setValue',null);
                       
                       
                     }
                     ,onLoadSuccess:function(){
                       //$('#userDeptId').combobox('setValues','dsfsdf');
                     }
                     >                  
                   </div> 
	        		     <div class="fitem">  
                     <label style="width:100px">岗位:</label>                                            
                     <input class="easyui-combobox" id="userTitleId" multiple="true"  name="titleIdString" style="width:200px;"  data-options="url:'',valueField:'id', textField:'name', multiple:true,panelHeight:'auto',mode:'remote' ">                  
                   </div>	        		     
        	  	   	 <div class="fitem">  
                     <label style="width:100px">状态<font color="red">*</font>:</label>  
                     <input class="easyui-combobox"  required="true" name="status" style="width:200px;"  data-options="data:__getConstantCategory('UserStatus'),valueField:'code', textField:'value', multiple:false,panelHeight:'auto',mode:'remote' ">
                   </div>  	        	  
                   <div class="fitem">  
                     <label style="width:100px">入职日期:</label>                       
                     <input name="hiredate" data-options="formatter:formateDate"  class="easyui-datebox">                       
                   </div>	   	
	        		     
	        		     <div class="fitem">  
                     <label style="width:100px">电话:</label>                                            
                     <input name="tel" class="easyui-box">                       
                   </div> 
	        		     <div class="fitem">  
                     <label style="width:100px">移动电话:</label>                                            
                     <input name="mobile" class="easyui-box">                       
                   </div> 
	        		     <div class="fitem">  
                     <label style="width:100px">内部电子邮箱:</label>                                            
                     <input name="email" class="easyui-box">                       
                   </div> 
	        		     <div class="fitem">  
                     <label style="width:100px">邮箱密码:</label>                                            
                     <input name="emailPasswd" class="easyui-box">                       
                   </div> 
	        		     <div class="fitem">  
                     <label style="width:100px">msn:</label>                                            
                     <input name="msn" class="easyui-box">                       
                   </div> 
	        		     <div class="fitem">  
                     <label style="width:100px">备注:</label>                                            
                     
                     <textarea name="comment" style="width:300px;height:100px"></textarea>               
                   </div> 
	        		      	        		     
        </form>  
        <div  style="text-align:center">  
          <a href="javascript:void(0)" id="btn-save" class="easyui-linkbutton" iconCls="icon-ok" ">Save</a>  
          <a href="javascript:void(0)" id="btn-close" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>  
        </div>
        -->
    </div>  
    <!-- edit form窗体（结束） -->  
    <!-- query form窗体(开始) -->  
    <div id="dlg_query" style="display:none;">  
    	  <!--
        
        <form id="fm_query" method="post" novalidate>  
            
              
	        		     
	        		     <div class="fitem">  
                     <label style="width:100px">姓名:</label>                                            
                     <input name="name" class="easyui-box">                       
                   </div> 
	        		     <div class="fitem">  
                     <label style="width:100px">分公司:</label>                                            
                     
                     <input class="easyui-combobox" id="branchCompanyIdString"  name="branchCompanyId" style="width:200px;"  data-options="url:'/auth/systemBranchCompany/listbranchcompany.do',valueField:'id', textField:'name', multiple:false,panelHeight:'auto',mode:'remote' ">                    
                   </div> 
	        		     <div class="fitem">  
                     <label style="width:100px">部门:</label>                                            
                     
                     <input class="easyui-combobox" id="userDeptId"  name="deptId" style="width:200px;"  data-options="url:'',valueField:'id', textField:'name', multiple:false,panelHeight:'auto',mode:'remote' ">                    
                   </div> 
	        		     <div class="fitem">  
                     <label style="width:100px">岗位:</label>                                            
                     <input class="easyui-combobox" id="userTitleId"  name="titleId" style="width:200px;"  data-options="url:'',valueField:'id', textField:'name', multiple:false,panelHeight:'auto',mode:'remote' ">                                       
                   </div>	        		     
        	  	   	 <div class="fitem">  
                     <label style="width:100px">状态:</label>                                            
                                          
                     <input class="easyui-combobox" name="status" style="width:200px;"  data-options="data:__getConstantCategory('UserStatus'),valueField:'code', textField:'value', multiple:false,panelHeight:'auto',mode:'remote' ">
                     
                   </div>      	
	        		            		     
              
              
        </form>
        <div  style="text-align:center">  
          <a href="javascript:void(0)" id="btn-query" class="easyui-linkbutton" iconCls="icon-ok" ">查询</a>  
          <a href="javascript:void(0)" id="btn-query-close" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>  
        </div>  
        -->
    </div> 
    <div id="dlg-role" style="display:none;">
    	   <!--
            <iframe  src="/auth/systemUser/userrole.do" style="width:99%;height:99%"></iframe>
         -->   
    </div> 
    <!-- query form窗体(结束) -->  
    
    <script type="text/javascript">  
        var url;  
        
        var url;  
        
        
        var optRoleWin = $.window({
		       		 title:"用户角色",
		       		 tplRef:"dlg-role",//这个属性指定模板id
		       		 height:550,	
		       		 width:500,	       		 
		       		 closed:true,		       		 
		       		 onComplete:function(){
		       		 	  //窗口里面的初始化,最好是在这个事件里面进行
		       		 	  var curWin=this;
		       		 	  
		       		 	  var iframe= this.find("iframe");
		       		 	  
		       		 	   iframe.load(function(){
		       		 	  	  
		       		 	  	    iframe.contents().find("#btn-close").click(function(){		       		 	  	
		       		 	  	      curWin.window('close');
		       		 	        });
		       		 	  	    iframe[0].contentWindow.closeWin=function(){
					                      	curWin.window('close');
					                      	  
				                };
				                iframe[0].contentWindow.refresh=function(){
					           	   if(curWin.openerWin.refresh) curWin.openerWin.refresh();
				                };
		       		 	  	   
		       		 	  	  
		       		 	  });
		       		 	  
		       		 	 
		       		   
		       		 }
		    });
        
        var optWin = $.window({
		       		 title:"新增公司员工",
		       		 tplRef:"dlg",//这个属性指定模板id
		       		 height:620,		       		 
		       		 width:500,
		       		 closed:true,		       		 
		       		 onComplete:function(){
		       		 	  //窗口里面的初始化,最好是在这个事件里面进行
		       		 	  var curWin=this;
		       		 	  var doForm=curWin.find('#fm');
		       		 	  curWin.doForm=doForm;
		       		 	  this.find("#btn-close").click(function(){		       		 	  	
		       		 	  	   curWin.window('close');
		       		 	  });
		       		 	  this.find("#branchCompanyIdString").combobox({
		       		 	    onSelect:function(rec){		       		 	  	
		       		 	  	    //alert($('#userDeptId'));              
		       		 	  	    //console.log($('#userDeptIda').combobox());
		       		 	  	    curWin.find("#userDeptId").combobox('reload', '/auth/systemBranchDept/deptlist.do?branchCompanyId='+curWin.find("#branchCompanyIdString").combobox('getValues'));                         
                        curWin.find("#userDeptId").combobox('setValues','');
		       		 	    }
		       		 	  }
		       		 	  );
		       		 	  
		       		 	  this.find("#userDeptId").combobox({
		       		 	    onSelect: function(rec){              
                        //alert(curWin.find("#userDeptId").combobox('getValues'));   
                        //console.log(rec);
                        curWin.find("#userTitleId").combobox('reload', '/auth/systemBranchTitle/titlelist.do?deptId='+curWin.find("#userDeptId").combobox('getValues'));  
                        curWin.find("#userTitleId").combobox('setValues','');
                    }
		       		 	  }
		       		 	  );
		       		 	  
		       		 	  
		       		 	       
		       		 	  
		       		 	  this.find("#btn-save").click(function(){		       		 	  	
		                 		  if (!doForm.form('validate')) return;
		                 		  
		                 		  doForm.form('submit',{  
                            url: curWin.url,  
                            onSubmit: function(){                              	  
                                return doForm.form('validate');  
                            },  
                            success: function(result){  
                                var result = eval('('+result+')');                      
                                if (result.success == true){  
                                    //$.messager.alert('信息',result.msg,'info');  
                                    alert(result.msg);
                                    curWin.window('close');
                                    curWin.openWin.reload();
                                    
                                } else {  
                                    //$.messager.alert('错误',result.msg,'error');
                                    alert(result.msg);
                                }  
                            }  
                       }); 		 
		              });
		       		   
		       		 }
		    });
		    
		    var queryWin = $.window({
		       		 title:"公司员工查询",
		       		 tplRef:"dlg_query",//这个属性指定模板id
		       		 height:200,		       		 
		       		 closed:true,		       		 
		       		 onComplete:function(){
		       		 	  //窗口里面的初始化,最好是在这个事件里面进行
		       		 	  var curWin=this;
		       		 	  var doForm=curWin.find('#fm_query');
		       		 	  curWin.doForm=doForm;
		       		 	  this.find("#btn-query-close").click(function(){		       		 	  	
		       		 	  	   curWin.window('close');
		       		 	  });
		       		 	  this.find("#btn-query").click(function(){
		       		 	  			                 		  
		                 		 //var formdata=$('#fm_query').formToArray(); 
		                 		 curWin.window('close');
		                 		 var formdata=curWin.find('#fm_query').formToArray();   		 
		                 		 curWin.openWin.query(formdata);
		              });
		       		   
		       		 }
		    });
        
        
        function add(){         	                        
            optWin.window('open'); 
            optWin.openWin=window;    
            optWin.url='/auth/systemUser/save.do';  
            optWin.doForm.form('clear');
            optWin.window('setTitle','新增公司员工');
        }  
        function doEdit(id){
        	optWin.window('open');
		             optWin.doForm.form('clear');
		             optWin.url='/auth/systemUser/update.do'; 
		             
		             
		             optWin.doForm.form({onLoadSuccess:function(data){
		             	   
		             	       optWin.doForm.find("#branchCompanyIdString").combobox('setValues',data.branchCompanyId+'');
		             	       optWin.doForm.find("#userDeptId").combobox('reload', '/auth/systemBranchDept/deptlist.do?branchCompanyId='+data.branchCompanyId+'');                         
                         optWin.doForm.find("#userDeptId").combobox('setValues',data.deptId+'');
                         optWin.doForm.find("#userTitleId").combobox('reload', '/auth/systemBranchTitle/titlelist.do?deptId='+data.deptId+'');  
                         optWin.doForm.find("#userTitleId").combobox('setValues',data.titleId+'');
		             	   
		             	   }
		             	});
		             optWin.doForm.form('load','/auth/systemUser/get.do?id='+id);   
		             optWin.openWin=window;
		             optWin.window('setTitle','修改公司员工');
		             console.log(optWin.doForm.find('input[name="account"]'));
		             //optWin.doForm.find('#branchCompanyIdString').combobox('setValues',''); 
		             optWin.doForm.find('input[name="account"]').attr("disabled",'true');
        }	
        
        function userRole(){  
        	  var rows = $('#dg').datagrid('getSelections');
            if (!rows||rows.length==0){
            	 $.messager.alert('提示','请选择要设置的用户','info');
            	 return;
            }
            if (!rows||rows.length>1){
            	 $.messager.alert('提示','不能选择多个用户','info');
            	 return;
            }
            
             optRoleWin.find('iframe')[0].contentWindow.location.href='/auth/systemUser/userrole.do?userId='+rows[0].id;    
        	   optRoleWin.window('open');
		         optRoleWin.openerWin=window;    
		         
		         
		         
        }		
        function edit(){  
            //var row = $('#dg').datagrid('getSelected');  
            var rows = $('#dg').datagrid('getSelections');
            if (!rows||rows.length==0){
            	 $.messager.alert('提示','请选择要修改的行','info');
            	 return;
            }
            if (!rows||rows.length>1){
            	 $.messager.alert('提示','不能选择多行','info');
            	 return;
            }
            if (rows){  
                 
		             doEdit(rows[0].id);
            }  
        }  
        function save(){          	   
        	  if (!$('#fm').form('validate')) return; 
            $('#fm').form('submit',{  
                url: url,  
                onSubmit: function(){  
                    return $(this).form('validate');  
                },  
                success: function(result){  
                    var result = eval('('+result+')');                      
                    if (result.success == true){  
                        $.messager.alert('信息',result.msg,'info');  
                        $('#dlg').dialog('close');      // close the dialog  
                        $('#dg').datagrid('reload');    // reload the user data  
                    } else {  
                        $.messager.alert('错误',result.msg,'error');
                    }  
                }  
            });  
        }  
        function deletes(){  
            var row = $('#dg').datagrid('getSelected');  
            
            var rows = $('#dg').datagrid('getSelections');  

            if (!rows||rows.length==0){
            	 $.messager.alert('提示','请选择要删除的行','info');
            	 return;
            }
            if (rows){  
                $.messager.confirm('重要提示','确定要删除?',function(r){  
                    if (r){  
                        $.post('/auth/systemUser/delete.do',{ids:getRecordArray(rows,'id').join(',')},function(result){  
                            if (result.success){  
                                $('#dg').datagrid('reload');    // reload the user data  
                            } else {  
                                 
                                $.messager.alert('错误',result.errorMsg,'error'); 
                            }  
                        },'json');  
                    }  
                });  
            }  
        }  
        function reload(){        	
        	  $('#dg').datagrid('reload');
        }
        function find(){  
              
                //$('#dlg_query').dialog('open').dialog('setTitle','查询');  
                
                //url = '/auth/systemUser/list.do';  
                 queryWin.window('open');   
                 queryWin.openWin=window; 
              
        } 
        	
        function query(formdata){  
                
                $('#dg').datagrid({
	                  queryParams: array2json(formdata)
                });
              
        }
        
        //生成grid的字段,需要字典的自动转换
        $('#dg').datagrid({
        	   columns:[[
        	           	           	         	   
        	   
        	   	  {field:'name',title:'姓名', width:100}
        	   	   ,{field:'account',title:'帐号', width:100}        	   	           	   	   
        	   	   ,{field:'branchCompanyName',title:'分公司', width:100}
        	   	   ,{field:'deptName',title:'部门', width:100}
        	   	   ,{field:'title',title:'岗位', width:100}
        	   	   ,{field:'status',title:'状态', width:100,
        	   		      formatter: function(value,row,index){
        	   		      	return __getConstantCategoryCodeValue('UserStatus', value);
        	   		      }
        	   	     }
        	   	   ,{field:'roles',title:'角色', width:100}
        	   	   ,{field:'tel',title:'电话', width:100}
        	   	   ,{field:'mobile',title:'移动电话', width:100}
        	   	   ,{field:'email',title:'电子邮箱', width:100}        	   	   
        	   	   ,{field:'msn',title:'msn', width:100}
        	   	   ,{field:'comment',title:'备注', width:100,hidden : true}
        	   	   ,{field:'hiredate',title:'入职日期', width:100}
        	   	   ,{field:'creator',title:'创建人', width:100}
        	   	   ,{field:'createDt',title:'创建时间', width:100}
        	   	   ,{field:'modifier',title:'修改人', width:100}
        	   	   ,{field:'modifiedDt',title:'修改时间', width:100,hidden : true}
        	   	   
        	   	
        	   	
        	   ]]
        	   ,pagesize:13
        	   ,pageNumber:3
        	   ,onDblClickRow: function(rowIndex, rowData){
        	    	//$('#dlg').dialog('open').dialog('setTitle','修改公司员工');                  
                //$('#fm').form('load','/auth/systemUser/get.do?id='+rowData.id);  
                //url = '/auth/systemUser/update.do';        	    	
                 doEdit(rowData.id);
        	    }
        }
        ); 
        //完成-生成grid的字段
        
        
        
    </script>  
     
     

     
     
     
</body>  
</html>